<template>
  <div>
    <div class="box">
      <div class="head">
        <div style="margin: 15px 0 15px 30px"><span style="width: 200px; height: 60px; font-size: 24px; font-weight: 530">搜索信息</span></div>
        <div class="scenic-spot-info">
          <!-- <el-input style="width: 400px" placeholder="请输入内容" v-model="search" class="input-with-select">
            <el-select v-model="selectVal" @change="changeSearch" slot="prepend" placeholder="请选择">
              <el-option label="景点名称" value="1"></el-option>
              <el-option label="所属城市" value="2"></el-option>
              <el-option label="景点等级" value="3"></el-option>
            </el-select>
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input> -->
          <!-- <div>
            <span class="title">景点名称</span>
            <el-input style="width: 200px" v-model="name"></el-input>
          </div>
          <div>
            <span class="title">所属城市</span>
            <el-input style="width: 200px" v-model="city_name"></el-input>
          </div>
          <div>
            <span class="title">景点等级</span>
            <el-input style="width: 200px" v-model="level"></el-input>
          </div>
          <div>
            <el-button @click="handleSearch" slot="append" icon="el-icon-search"></el-button>
          </div> -->
        </div>
        <div></div>
      </div>
      <div class="content">
        <div class="tabel">
          <el-button icon="el-icon-circle-plus-outline" size="mini" @click="dialogVisible = !dialogVisible" type="primary" style="margin-bottom: 10px">添加</el-button>
          <el-table :data="tableData" ref="singleTable" style="width: 100%" border max-height="370" height="370">
            <el-table-column fixed align="center" prop="id" label="ID"> </el-table-column>
            <el-table-column fixed align="center" prop="name" label="景点名称" min-width="140"> </el-table-column>
            <el-table-column align="center" prop="english_name" label="景点英文名" min-width="100"> </el-table-column>
            <el-table-column align="center" prop="city_name" label="城市"> </el-table-column>
            <el-table-column align="center" prop="level" label="等级"> </el-table-column>
            <el-table-column align="center" prop="title" label="标题" min-width="140"> </el-table-column>
            <el-table-column align="center" prop="play_time" label="游玩时间" min-width="130"> </el-table-column>
            <el-table-column align="center" prop="cost" label="预计费用"> </el-table-column>
            <el-table-column align="center" prop="am_allow_people" label="上午允许最大人数" min-width="180"> </el-table-column>
            <el-table-column align="center" prop="pm_allow_people" label="下午允许最大人数" min-width="180"> </el-table-column>
            <el-table-column align="center" label="操作" width="80px" fixed="right">
              <template slot-scope="scope">
                <el-button type="danger" icon="el-icon-delete" @click="del(scope)" circle></el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination"><el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagenow" :page-sizes="[100, 200, 300, 400]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="400"> </el-pagination></div>
        </div>
      </div>
    </div>
    <!-- 添加对话框 -->
    <el-dialog title="添加景点" :visible.sync="dialogVisible" width="40%">
      <el-form style="margin-right: 50px" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="demo-ruleForm">
        <el-form-item label="景点名称" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="景点英文名" prop="english_name">
          <el-input v-model="ruleForm.english_name"></el-input>
        </el-form-item>
        <el-form-item label="城市" prop="city_name">
          <el-input v-model="ruleForm.city_name"></el-input>
        </el-form-item>
        <el-form-item label="等级" prop="level">
          <el-input v-model="ruleForm.level"></el-input>
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="ruleForm.title"></el-input>
        </el-form-item>
        <el-form-item label="简介" prop="synopsis">
          <el-input v-model="ruleForm.synopsis"></el-input>
        </el-form-item>
        <el-form-item label="游玩时间" prop="play_time">
          <el-date-picker v-model="ruleForm.play_time" type="datetime" placeholder="选择日期时间" align="right"> </el-date-picker>
        </el-form-item>
        <el-form-item label="预计费用" prop="cost">
          <el-input v-model="ruleForm.cost"></el-input>
        </el-form-item>
        <el-form-item label="交通" prop="traffic">
          <el-input v-model="ruleForm.traffic"></el-input>
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="ruleForm.address"></el-input>
        </el-form-item>
        <el-form-item label="贴士" prop="tips">
          <el-input v-model="ruleForm.tips"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone_number">
          <el-input v-model="ruleForm.phone_number"></el-input>
        </el-form-item>
        <el-form-item label="官网" prop="official_website">
          <el-input v-model="ruleForm.official_website"></el-input>
        </el-form-item>
        <el-form-item label="上午允许最大人数" prop="am_allow_people">
          <el-input v-model="ruleForm.am_allow_people"></el-input>
        </el-form-item>
        <el-form-item label="下午允许最大人数" prop="pm_allow_people">
          <el-input v-model="ruleForm.pm_allow_people"></el-input>
        </el-form-item>
        <el-form-item label="所属区" prop="district">
          <el-input v-model="ruleForm.district"></el-input>
        </el-form-item>
        <el-form-item label="镇/县" prop="county">
          <el-input v-model="ruleForm.county"></el-input>
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="ruleForm.longitude"></el-input>
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="ruleForm.latitude"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addBtn">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      search: '',
      selectVal: '',
      city_name: '',
      name: '',
      level: '',
      dialogVisible: false,
      pagenow: 1,
      pagesize: 10,
      ruleForm: {
        id: '',
        name: '',
        city_name: '',
        level: '',
        english_name: '',
        title: '',
        synopsis: '',
        traffic: '',
        address: '',
        phone_number: '',
        official_website: '',
        district: '',
        county: '',
        longitude: 0,
        latitude: 0,
        play_time: '',
        cost: '',
        am_allow_people: '',
        pm_allow_people: '',
      },

      rules: {}, //表单验证规则
      tableData: [], //表格配置
    }
  },
  created() {
    // this.getGoodsList()
    this.getData()
  },
  mounted() {
    // this.load();  //加载
  },
  methods: {
    changeSearch(e) {
      switch (e) {
        case 1:
          this.name = this.search
          break
        case 2:
          this.city_name = this.search
          break
        case 3:
          this.level = this.search
          break
      }
    },
    // 根据分页获取对应的商品列表
    async getGoodsList() {
      const { data: res } = await this.$http.get('goods', {
        params: this.ruleForm,
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取列表失败')
      }
      this.goodslist = res.data.goods
      this.total = res.data.total
    },

    getData() {
      this.$http.get('manager/scenicSpot/queryScenicSpot', { params: { name: this.name, city_name: this.city_name, level: this.level } }).then((res) => {
        this.tableData = res.data.data
      })
      this.$nextTick(() => {
        this.$refs.singleTable.doLayout() // 解决表格错位
      })
    },
    //添加景点确认按钮
    addBtn() {
      let formData = new FormData()
      formData.append('name', this.ruleForm.name)
      formData.append('english_name', this.ruleForm.english_name)
      formData.append('city_name', this.ruleForm.city_name)
      formData.append('level', this.ruleForm.level)
      formData.append('title', this.ruleForm.title)
      formData.append('synopsis', this.ruleForm.synopsis)
      formData.append('traffic', this.ruleForm.traffic)
      formData.append('address', this.ruleForm.address)
      formData.append('phone_number', this.ruleForm.phone_number)
      formData.append('official_website', this.ruleForm.official_website)
      formData.append('district', this.ruleForm.district)
      formData.append('county', this.ruleForm.county)
      formData.append('longitude', this.ruleForm.longitude)
      formData.append('latitude', this.ruleForm.latitude)
      formData.append('play_time', this.ruleForm.play_time)
      formData.append('cost', this.ruleForm.cost)
      formData.append('am_allow_people', this.ruleForm.am_allow_people)
      formData.append('pm_allow_people', this.ruleForm.pm_allow_people)
      this.dialogVisible = false
      this.$http.post('manager/scenicSpot/addScenicSpot', formData).then((res) => {
        console.log(res, '55')
      })
    },
    // 删除
    del(row) {
      console.log(row)
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {})
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },
    handleSizeChange(e) {},
    handleCurrentChange(e) {},
    //查询景点
    handleSearch() {
      this.getData()
    },
  },
}
</script>

<style scoped>
.box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.head {
  /* flex: 1; */
  width: 100%;
  background: #fff;
}
.content {
  /* flex: 3; */
  width: 100%;
  background: #fff;
  margin-top: 10px;
  padding-top: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.tabel {
  width: 97%;
  height: 465px;
  margin: auto;
}
.title {
  font-size: 18px;
  font-weight: 520;
  color: #999;
}
p {
  color: #409eff;
}
.pagination {
  margin-top: 10px;
  height: 50px;
  text-align: right;
}
.scenic-spot-info {
  /* display: flex;
  justify-content: space-around;
  align-items: center; */
  height: 70px;
  margin-left: 30px;
}
</style>
